/**
 * Created by zhangsanfeng on 2020/07/02.
 */

import { Message } from 'element-ui'

export const tool = {

  mathRandom: function (min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min)
  },

  // success warning error
  message (text, type, callback) {
    Message({
      message: text,
      type: type,
      duration: 2000,
      onClose: () => {
        callback && callback()
      }
    })
  },

  /* 数组去重
    param:{
        arr: 入参数组,
        key: 主键
    }
  */
  unique (arr) {
    var result = []
    var obj = {}
    for (var i = 0; i < arr.length; i++) {
      if (!obj[arr[i].name]) {
        result.push(arr[i])
        obj[arr[i].name] = true
      }
    }
    return result
  }
}
